*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

* Authors: Ranjit Lall & David Vilalta

* Paper: Varieties of Anxieties: Disaggregating Emotion and Voting Behavior in the COVID-19 Era

* What for: Cleans and formats dataset coming from original survey experiment

*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

clear all 

* Insert folder path
global folder ".../Insert folder path"


cd "${folder}"

*Local folders
global dta "Final_data/"
global tables "Results/Tables/"
global figures "Results/Figures/"


import delimited using "Raw_data/Survey_Experiment/responses_cleaned.csv", encoding(UTF-8) clear

gen health_tr=0
replace health_tr=1 if condition=="Health"

gen econ_tr=0
replace econ_tr=1 if condition=="Economy"

gen vote_pl=0
replace vote_pl=1 if candidate_choice=="Tengo una ligera preferencia por el candidato A (a favor del confinamiento)"
replace vote_pl=1 if candidate_choice=="Tengo una gran preferencia por el candidato A (a favor del confinamiento)"

gen vote_al=0
replace vote_al=1 if candidate_choice=="Tengo una ligera preferencia por el candidato B (anti-confinamiento)"
replace vote_al=1 if candidate_choice=="Tengo una gran preferencia por el candidato B (anti-confinamiento)"


gen female=0
replace female=1 if sex=="Femenino"

gen white=0
replace white=1 if ethnicity=="Blanco"

gen infection=0
replace infection=1 if personal_infection=="Si"

gen pp=0
replace pp=1 if party_affiliation=="Un poco con el Partido Popular (PP)" | party_affiliation=="Totalmente con el Partido Popular (PP)" | party_affiliation=="Partido Popular (PP)"

gen psoe=0
replace psoe=1 if party_affiliation=="Un poco con el Partido Socialista Obrero Espanol (PSOE)" | party_affiliation=="Totalmente con el Partido Socialista Obrero Espanol (PSOE)" | party_affiliation=="Partido Socialista Obrero Espanol (PSOE)"

gen vox=0
replace vox=1 if party_affiliation=="Un poco con el Vox" | party_affiliation=="Totalmente con Vox" | party_affiliation=="Vox"

gen podemos=0
replace podemos=1 if party_affiliation=="Un poco con Podemos / Sumar" | party_affiliation=="Totalmente con Podemos / Sumar" | party_affiliation=="Podemos / Sumar"

gen underlying=0
replace underlying=1 if underlying_condition=="Si"

gen poor_rich=0
replace poor_rich=1 if income=="0-9999" | income=="150000+" | income=="100000-149999" | income=="60000-79000" | income=="80000-99999"

gen primary_tertiary=0
replace primary_tertiary=1 if education=="Sin estudios" | education=="Estudios primarios" | education=="Graduado o escuela profesional"

encode education, gen(education_n)
drop education
rename education_n education

gen educ_1=0
replace educ_1=1 if education==1
gen educ_2=0
replace educ_2=1 if education==2
gen educ_3=0
replace educ_3=1 if education==3
gen educ_4=0
replace educ_4=1 if education==4
gen educ_5=0
replace educ_5=1 if education==5
gen educ_6=0
replace educ_6=1 if education==6
gen educ_7=0
replace educ_7=1 if education==7

label var vote_pl "Vote for candidate A"
label var vote_al "Vote for candidate B"
label var health_tr "Health Prime"
label var econ_tr "Economic Prime"
label var age "Age"
label var female "Gender: Female"
label var white "Race - white"
label var pp "Party - PP"
label var psoe "Party - PSOE"
label var vox "Party - Vox"
label var podemos "Party - Podemos"
label var education "Education level"
label var primary_tertiary "Primary / Tertiary education"
label var poor_rich "Poor / Rich"
label var underlying "Underlying health condition"
label var infection "Infected by COVID-19"
label var educ_1 "Education: High School"
label var educ_2 "Education: Primary Studies"
label var educ_3 "Education: Vocational Training"
label var educ_4 "Education: Graduate Studies"
label var educ_5 "Education: No Studies"
label var educ_6 "Education: Community College"
label var educ_7 "Education: Undergraduate Studies"
label var health_anxiety "Health Anxiety"
label var econ_anxiety "Economic Anxiety"
label var duration "Duration"
label var condition "Condition"
label var candidate_choice "Candidate choice"
label var sex "Sex"
label var ethnicity "Ethnicity"
label var income "Income level"
label var party_affiliation "Party affiliation"
label var personal_infection "Infection (personal)"
label var close_infection "Infection (close)"
label var underlying_condition "Underlying health condition"



save ${dta}Finaldata_survey, replace
